home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_09_05
/
9n05070a
< prev
next >
Wrap
Text File
|
1991-03-02
|
1KB
|
61 lines
#include <stdio.h>
char EXEName[30] = "[d:\path\]exefile.exe";
long DataPosition;
FILE *EXEfile;
char *DataErrors[6] =
{
"OK",
"Unable to open EXE file",
"Unable to read Header info",
"Unable to read DataSeg",
"Unable to write DataSeg",
"Unable to close EXE file"
};
int SetDataPosition()
{
int Header[3];
if((EXEfile=fopen(EXEName, "r+b"))==NULL) /* Open the .EXE */
return 1;
if(fread(Header, sizeof(int), 3, EXEfile) != 3) /*Read*/
return 2; /* the first 3 integer of the Header */
DataPosition = 512*(Header[2]-1) + Header[1] + 1;
/* Compute the position of the Data */
fseek(EXEfile, DataPosition, SEEK_SET);
return 0;
}
int ReadDataSeg(int Length, void *DataBuffer)
{
if(fread(DataBuffer, (size_t)Length, 1, EXEfile) !=1)
return 3; /*Read the data from the .EXE file */
return 0;
}
int WriteDataSeg(int Length, void *DataBuffer)
{
if(fwrite(DataBuffer, (size_t)Length, 1, EXEfile) != 1)
return 4; /* Write the data to the .EXE file*/
return 0;
}
void SeekDataSeg(long Offset)
{
fseek(EXEfile, DataPosition+Offset, SEEK_SET);
} /* Seek a position in the DataSeg */
long TellDataSeg()
{
return ftell(EXEfile)-DataPosition;
} /* Tell the current position in the DataSeg */
int CloseDataSeg()
{
if(fclose(EXEfile)) return 5;
} /* Close the EXE file */